//
// Created on 2024/11/14.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#include "ui_motion_animation_capi_test.h"
#include "common/common.h"
#include <arkui/native_interface.h>
#include <arkui/native_type.h>
#include <string>
#include <sstream>

static ArkUI_AnimateOption* animateOption = nullptr;
static ArkUI_NativeAnimateAPI_1 *animateApi = nullptr;
static ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr;
static ArkUI_NodeHandle createAnimateNode = nullptr;
static ArkUI_NodeHandle createAnimateButton = nullptr;
static ArkUI_NodeHandle createAnimateListText = nullptr;
static ArkUI_NodeHandle createAnimateProgressText = nullptr;
static ArkUI_NodeHandle createAnimateFlex01Text = nullptr;
static ArkUI_NodeHandle createAnimateFlex02Text = nullptr;
static ArkUI_NodeHandle createAnimateFlex03Text = nullptr;
static ArkUI_NodeHandle text = nullptr;
static ArkUI_NodeType g_AnimationType = ARKUI_NODE_BUTTON;
static ArkUI_NodeType nodeType = ARKUI_NODE_BUTTON;

static int NUMBER_1000 = 1000;
static int NUMBER_5000 = 5000;
static int NUMBER_CREATE_ANIMATE = 9905;
static int32_t NUMBER_SCALE_BUTTON_EVENT = 9001;
static int32_t NUMBER_BACKGROUNDCOLOR_BUTTON_EVENT = 9002;
static int32_t NUMBER_TRANSLATE_BUTTON_EVENT = 9003;
static int32_t NUMBER_FONTSIZE_BUTTON_EVENT = 9004;
static int32_t NUMBER_FONTCOLOR_BUTTON_EVENT = 9005;
static int32_t NUMBER_ROTATE_BUTTON_EVENT = 9006;
static int32_t NUMBER_OPACITY_BUTTON_EVENT = 9007;

struct UserData{
    int32_t data;
};

namespace ArkUICApiDemo {

static auto CreateBaseNodeWithIDAndName(ArkUI_NativeNodeAPI_1 *nodeAPI, std::string componentId,
    std::string buttonName, ArkUI_NodeType type = ARKUI_NODE_BUTTON)
{
    // 创建组件并添加到容器内
    auto nodeBase = nodeAPI->createNode(type);
    ArkUI_AttributeItem idStr;
    idStr.string = componentId.c_str();
    nodeAPI->setAttribute(nodeBase, NODE_ID, &idStr);
    if (type != ARKUI_NODE_LIST && type != ARKUI_NODE_FLEX && type != ARKUI_NODE_SCROLL && type != ARKUI_NODE_COLUMN
        && type != ARKUI_NODE_SWIPER && type != ARKUI_NODE_ROW) {
        ArkUI_AttributeItem text_item = {nullptr, 0, buttonName.c_str()};
        nodeAPI->setAttribute(nodeBase, NODE_BUTTON_LABEL, &text_item);
    }
    if (type == ARKUI_NODE_IMAGE) {
        g_AnimationType = ARKUI_NODE_IMAGE;
        ArkUI_AttributeItem src_item = {};
        src_item.string = "resource://media/icon.png";
        nodeAPI->setAttribute(nodeBase, NODE_IMAGE_SRC, &src_item);
        ArkUI_NumberValue border_value[] = {{.f32 = 1}};
        ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_BORDER_WIDTH, &border_item);
        return nodeBase;
    }
    if (type == ARKUI_NODE_IMAGE_SPAN) {
        g_AnimationType = ARKUI_NODE_IMAGE_SPAN;
        ArkUI_AttributeItem src_item = {};
        src_item.string = "resource://media/icon.png";
        nodeAPI->setAttribute(nodeBase, NODE_IMAGE_SPAN_SRC, &src_item);
        ArkUI_NumberValue border_value[] = {{.f32 = 1}};
        ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_BORDER_WIDTH, &border_item);
        return nodeBase;
    }
    if (type == ARKUI_NODE_TEXT) {
        g_AnimationType = ARKUI_NODE_TEXT;
        ArkUI_AttributeItem content_item = {.string = "ARKUI_NODE_TEXT"};
        nodeAPI->setAttribute(nodeBase, NODE_TEXT_CONTENT, &content_item);
        ArkUI_NumberValue border_value[] = {{.f32 = 1}};
        ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_BORDER_WIDTH, &border_item);
        return nodeBase;
    }
    if (type == ARKUI_NODE_SPAN) {
        g_AnimationType = ARKUI_NODE_SPAN;
        auto text = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item = {.string = buttonName.c_str()};
        nodeAPI->setAttribute(nodeBase, NODE_SPAN_CONTENT, &content_item);
        nodeAPI->addChild(text, nodeBase);
        ArkUI_NumberValue border_value[] = {{.f32 = 1}};
        ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_BORDER_WIDTH, &border_item);
        ArkUI_AttributeItem id_item = {.string = "OnClickButton0120_SPAN"};
        nodeAPI->setAttribute(text, NODE_ID, &id_item);
        return text;
    }
    if (type == ARKUI_NODE_LIST) {
        g_AnimationType = ARKUI_NODE_LIST;
        auto listItem = nodeAPI->createNode(ARKUI_NODE_LIST_ITEM);
        createAnimateListText = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem text_item = {nullptr, 0, buttonName.c_str()};
        nodeAPI->setAttribute(createAnimateListText, NODE_TEXT_CONTENT, &text_item);
        nodeAPI->addChild(listItem, createAnimateListText);
        nodeAPI->addChild(nodeBase, listItem);
        return nodeBase;
    }
    if (type == ARKUI_NODE_LOADING_PROGRESS) {
        g_AnimationType = ARKUI_NODE_LOADING_PROGRESS;
        createAnimateProgressText = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item = {.string = buttonName.c_str()};
        nodeAPI->setAttribute(createAnimateProgressText, NODE_TEXT_CONTENT, &content_item);
        return nodeBase;
    }
    if (type == ARKUI_NODE_FLEX) {
        g_AnimationType = ARKUI_NODE_FLEX;
        ArkUI_NumberValue flexDirection[] = {{.i32 = ARKUI_FLEX_DIRECTION_ROW_REVERSE}, {.i32 = 0}, {.i32 = ARKUI_FLEX_ALIGNMENT_CENTER}};
        ArkUI_AttributeItem flex_label_item = {flexDirection,
            sizeof(flexDirection) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_FLEX_OPTION, &flex_label_item);

        createAnimateFlex01Text = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item = {.string = (buttonName + "01").c_str()};
        nodeAPI->setAttribute(createAnimateFlex01Text, NODE_TEXT_CONTENT, &content_item);

        createAnimateFlex02Text = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item1 = {.string = (buttonName + "02").c_str()};
        nodeAPI->setAttribute(createAnimateFlex02Text, NODE_TEXT_CONTENT, &content_item1);

        createAnimateFlex03Text = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item2 = {.string = (buttonName + "03").c_str()};
        nodeAPI->setAttribute(createAnimateFlex03Text, NODE_TEXT_CONTENT, &content_item2);

        nodeAPI->addChild(nodeBase, createAnimateFlex01Text);
        nodeAPI->addChild(nodeBase, createAnimateFlex02Text);
        nodeAPI->addChild(nodeBase, createAnimateFlex03Text);
        return nodeBase;
    }
    if (type == ARKUI_NODE_STACK) {
        g_AnimationType = ARKUI_NODE_STACK;

        createAnimateFlex01Text = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item = {.string = "AAA"};
        nodeAPI->setAttribute(createAnimateFlex01Text, NODE_TEXT_CONTENT, &content_item);

        createAnimateFlex02Text = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item1 = {.string = "BBB"};
        nodeAPI->setAttribute(createAnimateFlex02Text, NODE_TEXT_CONTENT, &content_item1);

        createAnimateFlex03Text = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item2 = {.string = "CCC"};
        nodeAPI->setAttribute(createAnimateFlex03Text, NODE_TEXT_CONTENT, &content_item2);

        nodeAPI->addChild(nodeBase, createAnimateFlex01Text);
        nodeAPI->addChild(nodeBase, createAnimateFlex02Text);
        nodeAPI->addChild(nodeBase, createAnimateFlex03Text);
        return nodeBase;
    }
    if (type == ARKUI_NODE_SCROLL) {
        g_AnimationType = ARKUI_NODE_SCROLL;
        ArkUI_NumberValue attribute_value[] = {{.i32 = ARKUI_SCROLL_BAR_DISPLAY_MODE_ON}};
        ArkUI_AttributeItem attribute_item = {attribute_value, sizeof(attribute_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_SCROLL_BAR_DISPLAY_MODE, &attribute_item);
        ArkUI_NumberValue scroll_bar_color_value[] = {{.u32 = 0xff00ff00}};
        ArkUI_AttributeItem bar_color_item = {scroll_bar_color_value,
                                              sizeof(scroll_bar_color_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_SCROLL_BAR_COLOR, &bar_color_item);
        ArkUI_NumberValue border_value[] = {{.f32 = 1}};
        ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_BORDER_WIDTH, &border_item);

        createAnimateNode = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item = {.string = "ARKUI_NODE_SCROLL"};
        nodeAPI->setAttribute(createAnimateNode, NODE_TEXT_CONTENT, &content_item);

        auto childColumn = nodeAPI->createNode(ARKUI_NODE_COLUMN);
        auto childButton = nodeAPI->createNode(ARKUI_NODE_BUTTON);

        ArkUI_NumberValue button_width_value[] = {{.f32 = 50}};
        ArkUI_NumberValue button_height_value[] = {{.f32 = 100}};
        ArkUI_AttributeItem button_width_item = {button_width_value,
                                                 sizeof(button_width_value) / sizeof(ArkUI_NumberValue)};
        ArkUI_AttributeItem button_height_item = {button_height_value,
                                                  sizeof(button_height_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(childButton, NODE_WIDTH, &button_width_item);
        nodeAPI->setAttribute(childButton, NODE_HEIGHT, &button_height_item);

        nodeAPI->addChild(childColumn, createAnimateNode);
        nodeAPI->addChild(childColumn, childButton);
        nodeAPI->addChild(nodeBase, childColumn);
        return nodeBase;
    }
    if (type == ARKUI_NODE_SWIPER) {
        g_AnimationType = ARKUI_NODE_SWIPER;
        ArkUI_NumberValue border_value[] = {{.f32 = 1}};
        ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_BORDER_WIDTH, &border_item);

        createAnimateFlex01Text = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item1 = {.string = "SCROLL_PAGE1"};
        nodeAPI->setAttribute(createAnimateFlex01Text, NODE_TEXT_CONTENT, &content_item1);
        createAnimateFlex02Text = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item2 = {.string = "SCROLL_PAGE2"};
        nodeAPI->setAttribute(createAnimateFlex02Text, NODE_TEXT_CONTENT, &content_item2);

        nodeAPI->addChild(nodeBase, createAnimateFlex01Text);
        nodeAPI->addChild(nodeBase, createAnimateFlex02Text);
        return nodeBase;
    }
    if (type == ARKUI_NODE_COLUMN) {
        g_AnimationType = ARKUI_NODE_COLUMN;
        ArkUI_NumberValue border_value[] = {{.f32 = 1}};
        ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_BORDER_WIDTH, &border_item);

        createAnimateNode = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item = {.string = "ARKUI_NODE_COLUMN"};
        nodeAPI->setAttribute(createAnimateNode, NODE_TEXT_CONTENT, &content_item);
        nodeAPI->addChild(nodeBase, createAnimateNode);
        return nodeBase;
    }
    if (type == ARKUI_NODE_ROW) {
        g_AnimationType = ARKUI_NODE_ROW;
        ArkUI_NumberValue border_value[] = {{.f32 = 1}};
        ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_BORDER_WIDTH, &border_item);

        createAnimateNode = nodeAPI->createNode(ARKUI_NODE_TEXT);
        ArkUI_AttributeItem content_item = {.string = "ARKUI_NODE_ROW"};
        nodeAPI->setAttribute(createAnimateNode, NODE_TEXT_CONTENT, &content_item);
        nodeAPI->addChild(nodeBase, createAnimateNode);
        return nodeBase;
    }
    if (type == ARKUI_NODE_TEXT_AREA) {
        g_AnimationType = ARKUI_NODE_TEXT_AREA;
        ArkUI_AttributeItem content_item = {.string = "ARKUI_NODE_TEXT_AREA"};
        nodeAPI->setAttribute(nodeBase, NODE_TEXT_AREA_TEXT, &content_item);
        ArkUI_NumberValue border_value[] = {{.f32 = 1}};
        ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeBase, NODE_BORDER_WIDTH, &border_item);
        return nodeBase;
    }
    return nodeBase;
}

static void SetScaleButtonEvent(ArkUI_NodeHandle nodeHandle)
{
    ArkUI_NumberValue scale[] = {{.f32 = 1.5f}, {.f32 = 1.3f}}; // 2 is scale value
    ArkUI_AttributeItem rotate_label_item = {scale, sizeof(scale) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(nodeHandle, NODE_SCALE, &rotate_label_item);
}

static void SetBackGroundButtonEvent(ArkUI_NodeHandle nodeHandle)
{
    if (g_AnimationType == ARKUI_NODE_LOADING_PROGRESS) {
        ArkUI_NumberValue background_color_value[] = {{.u32 = COLOR_RED}};
        ArkUI_AttributeItem background_color_item = {background_color_value,
            sizeof(background_color_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(createAnimateButton, NODE_LOADING_PROGRESS_COLOR, &background_color_item);
    } else {
        ArkUI_NumberValue background_color_value[] = {{.u32 = COLOR_RED}};
        ArkUI_AttributeItem background_color_item = {background_color_value,
            sizeof(background_color_value) / sizeof(ArkUI_NumberValue)};
        nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item);
    }
}

static void SetTranslateButtonEvent(ArkUI_NodeHandle nodeHandle)
{
    ArkUI_NumberValue translate[] = {{.f32 = 150}, {.f32 = 150}}; // 150 is translate position
    ArkUI_AttributeItem translate_label_item = {translate,
        sizeof(translate) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(nodeHandle, NODE_OFFSET, &translate_label_item);
}

static void SetFontSizeButtonEvent(ArkUI_NodeHandle nodeHandle)
{
    ArkUI_NumberValue fontSize[] = {{.f32 = 40.f}}; // 40 is font size
    ArkUI_AttributeItem fontSize_label_item = {fontSize,
        sizeof(fontSize) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(nodeHandle, NODE_FONT_SIZE, &fontSize_label_item);
}

static void SetFontColorButtonEvent(ArkUI_NodeHandle nodeHandle)
{
    ArkUI_NumberValue fontColor[] = {{.u32 = COLOR_YELLOW}};
    ArkUI_AttributeItem fontColor_label_item = {fontColor,
        sizeof(fontColor) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(nodeHandle, NODE_FONT_COLOR, &fontColor_label_item);
}

static void SetRotateButtonEvent(ArkUI_NodeHandle nodeHandle)
{
    ArkUI_NumberValue rotate[] = {
        -1.0f, 0.0f, 0.0f, 0.f,
        0.0f, 1.0f, 0.f, 0.f,
        0.0f, 0.0f, -1.0f, 0.0f,
        0.0f, 0.0f, 0.0f, 1.0f};
    ArkUI_AttributeItem rotate_label_item = {rotate,
        sizeof(rotate) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(nodeHandle, NODE_TRANSFORM, &rotate_label_item);
}

static void SetOpacityButtonEvent(ArkUI_NodeHandle nodeHandle)
{
    ArkUI_NumberValue background_color_value[] = {{.u32 = COLOR_RED}};
    ArkUI_AttributeItem background_color_item = {background_color_value,
        sizeof(background_color_value) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(nodeHandle, NODE_BACKGROUND_COLOR, &background_color_item);
    ArkUI_NumberValue opacity[] = {{.f32 = 0.5}}; // 0.5 is opacity value
    ArkUI_AttributeItem opacity_label_item = {opacity,
        sizeof(opacity) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(nodeHandle, NODE_OPACITY, &opacity_label_item);
}

static void OnEventReceive(ArkUI_NodeEvent *event)
{
    if (event == nullptr) {
        OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "AnimatorOnEventReceive",
            "OnEventReceive: event is null");
        return;
    }
    OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI);
    int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event);
    OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OnEventReceive", "get eventId  %{public}d", eventId);
    auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event);
    if (eventId == NUMBER_SCALE_BUTTON_EVENT) {
        SetScaleButtonEvent(createAnimateButton);
    }
    if (eventId == NUMBER_BACKGROUNDCOLOR_BUTTON_EVENT) {
        SetBackGroundButtonEvent(createAnimateButton);
    }
    if (eventId == NUMBER_TRANSLATE_BUTTON_EVENT) {
        SetTranslateButtonEvent(createAnimateButton);
    }
    if (eventId == NUMBER_FONTSIZE_BUTTON_EVENT) {
        if (g_AnimationType == ARKUI_NODE_LIST) {
            SetFontSizeButtonEvent(createAnimateListText);
        }
        if (g_AnimationType == ARKUI_NODE_FLEX || g_AnimationType == ARKUI_NODE_STACK) {
            SetFontSizeButtonEvent(createAnimateFlex01Text);
            SetFontSizeButtonEvent(createAnimateFlex02Text);
            SetFontSizeButtonEvent(createAnimateFlex03Text);
        }
        if (g_AnimationType == ARKUI_NODE_SWIPER) {
            SetFontSizeButtonEvent(createAnimateFlex01Text);
            SetFontSizeButtonEvent(createAnimateFlex02Text);
        }
        if (g_AnimationType == ARKUI_NODE_SCROLL) {
            SetFontSizeButtonEvent(createAnimateNode);
        }
        if (g_AnimationType == ARKUI_NODE_COLUMN) {
            SetFontSizeButtonEvent(createAnimateNode);
        }
        if (g_AnimationType == ARKUI_NODE_ROW) {
            SetFontSizeButtonEvent(createAnimateNode);
        }
        if (g_AnimationType == ARKUI_NODE_LOADING_PROGRESS) {
            SetFontSizeButtonEvent(createAnimateProgressText);
        }
        SetFontSizeButtonEvent(createAnimateButton);
    }
    if (eventId == NUMBER_FONTCOLOR_BUTTON_EVENT) {
        if (g_AnimationType == ARKUI_NODE_LIST) {
            SetFontColorButtonEvent(createAnimateListText);
        }
        if (g_AnimationType == ARKUI_NODE_FLEX || g_AnimationType == ARKUI_NODE_STACK) {
            SetFontColorButtonEvent(createAnimateFlex01Text);
            SetFontColorButtonEvent(createAnimateFlex02Text);
            SetFontColorButtonEvent(createAnimateFlex03Text);
        }
        if (g_AnimationType == ARKUI_NODE_SWIPER) {
            SetFontColorButtonEvent(createAnimateFlex01Text);
            SetFontColorButtonEvent(createAnimateFlex02Text);
        }
        if (g_AnimationType == ARKUI_NODE_SCROLL) {
            SetFontColorButtonEvent(createAnimateNode);
        }
        if (g_AnimationType == ARKUI_NODE_COLUMN) {
            SetFontColorButtonEvent(createAnimateNode);
        }
        if (g_AnimationType == ARKUI_NODE_ROW) {
            SetFontColorButtonEvent(createAnimateNode);
        }
        if (g_AnimationType == ARKUI_NODE_LOADING_PROGRESS) {
            SetFontColorButtonEvent(createAnimateProgressText);
        }
        SetFontColorButtonEvent(createAnimateButton);
    }
    if (eventId == NUMBER_ROTATE_BUTTON_EVENT) {
        SetRotateButtonEvent(createAnimateButton);
    }
    if (eventId == NUMBER_OPACITY_BUTTON_EVENT) {
        SetOpacityButtonEvent(createAnimateButton);
    }
    if (eventId == NUMBER_CREATE_ANIMATE) {
        if (g_AnimationType == ARKUI_NODE_LOADING_PROGRESS) {
            OH_ArkUI_AnimateOption_SetDuration(animateOption, 2000);
        }
        UserData* onFinishUser = new UserData;
        onFinishUser->data = 101; // 101 is onFinishUserData
        //设置完成的回调
        ArkUI_AnimateCompleteCallback* completeCallback = new ArkUI_AnimateCompleteCallback;
        completeCallback->userData = onFinishUser;
        completeCallback->type = ARKUI_FINISH_CALLBACK_REMOVED;
        completeCallback->callback = [](void* userData) {
            OH_LOG_Print(LOG_APP,LOG_ERROR, LOG_PRINT_DOMAIN, "Manager","CreateNativeNode onFinishCallback %{public}d",
                reinterpret_cast<UserData*>(userData)->data);
        };
        //用户自定义参数
        UserData* eventUser = new UserData;
        eventUser->data = 201; // 201 is userData
        static bool isback = true;
        ArkUI_ContextCallback* update = new ArkUI_ContextCallback;
        update->userData = eventUser;
        update->callback = [](void* user) {
            if (g_AnimationType == ARKUI_NODE_LOADING_PROGRESS) {
                ArkUI_NumberValue value[] = {{.i32 = true}};
                ArkUI_AttributeItem item = {value, sizeof(value) / sizeof(ArkUI_NumberValue)};
                nodeAPI->setAttribute(createAnimateButton, NODE_LOADING_PROGRESS_ENABLE_LOADING, &item);
            }
            ArkUI_NumberValue custom_widthValue[] = { 200 }; // 100 is custom width
            ArkUI_AttributeItem custom_widthItem = {custom_widthValue, 1};
            ArkUI_NumberValue custom_heightValue[] = { 400 }; // 200 is custom height
            ArkUI_AttributeItem custom_heightItem = { custom_heightValue, 1};
            nodeAPI->setAttribute(createAnimateButton, NODE_WIDTH, &custom_widthItem);
            nodeAPI->setAttribute(createAnimateButton, NODE_HEIGHT, &custom_heightItem);
        };
        ArkUI_ContextHandle contextHandle = OH_ArkUI_GetContextByNode(createAnimateButton);
        animateApi->animateTo(contextHandle, animateOption, update, completeCallback);
    }
}

static void CreateAnimateOption(float tempo, int32_t iteration)
{
    animateOption = OH_ArkUI_AnimateOption_Create();
    // 设置持续时间
    OH_ArkUI_AnimateOption_SetDuration(animateOption, NUMBER_5000);
    // 设置播放速度
    OH_ArkUI_AnimateOption_SetTempo(animateOption, tempo); // 1.1 means animate tempo
    // 设置动画曲线
    OH_ArkUI_AnimateOption_SetCurve(animateOption, ArkUI_AnimationCurve::ARKUI_CURVE_FAST_OUT_LINEAR_IN);
    // 设置延迟时间
    OH_ArkUI_AnimateOption_SetDelay(animateOption, NUMBER_1000);
    // 设置播放次数
    OH_ArkUI_AnimateOption_SetIterations(animateOption, iteration);
    // 设置播放模式
    OH_ArkUI_AnimateOption_SetPlayMode(animateOption, ArkUI_AnimationPlayMode::ARKUI_ANIMATION_PLAY_MODE_NORMAL);
}

static void MotionButtonHandle(ArkUI_NativeNodeAPI_1 *nodeAPI, std::string componentId, ArkUI_NodeHandle& rootNode)
{
    // 背景色变化
    auto backGroundColorButton = CreateBaseNodeWithIDAndName(nodeAPI, componentId + "_1", "背景色变化");
    // 透明度
    auto opacityButton = CreateBaseNodeWithIDAndName(nodeAPI, componentId + "_2", "渐隐");
    // 字体大小变化
    auto fontSizeButton = CreateBaseNodeWithIDAndName(nodeAPI, componentId + "_3", "字体大小变化");
    // 字体颜色变化
    auto fontColorButton = CreateBaseNodeWithIDAndName(nodeAPI, componentId + "_4", "字体颜色变化");
    // 旋转
    auto rotateButton = CreateBaseNodeWithIDAndName(nodeAPI, componentId + "_5", "旋转");
    // 缩放
    auto onScaleButton = CreateBaseNodeWithIDAndName(nodeAPI, componentId + "_6", "缩放");
    // 平移
    auto translateButton = CreateBaseNodeWithIDAndName(nodeAPI, componentId + "_7", "平移");
    // 注册事件
    nodeAPI->registerNodeEvent(createAnimateButton, NODE_ON_CLICK, NUMBER_CREATE_ANIMATE, nullptr);
    nodeAPI->registerNodeEvent(onScaleButton, NODE_ON_CLICK, NUMBER_SCALE_BUTTON_EVENT, nullptr);
    nodeAPI->registerNodeEvent(backGroundColorButton, NODE_ON_CLICK, NUMBER_BACKGROUNDCOLOR_BUTTON_EVENT, nullptr);
    nodeAPI->registerNodeEvent(translateButton, NODE_ON_CLICK, NUMBER_TRANSLATE_BUTTON_EVENT, nullptr);
    nodeAPI->registerNodeEvent(fontSizeButton, NODE_ON_CLICK, NUMBER_FONTSIZE_BUTTON_EVENT, nullptr);
    nodeAPI->registerNodeEvent(fontColorButton, NODE_ON_CLICK, NUMBER_FONTCOLOR_BUTTON_EVENT, nullptr);
    nodeAPI->registerNodeEvent(rotateButton, NODE_ON_CLICK, NUMBER_ROTATE_BUTTON_EVENT, nullptr);
    nodeAPI->registerNodeEvent(opacityButton, NODE_ON_CLICK, NUMBER_OPACITY_BUTTON_EVENT, nullptr);
    OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi);
    CreateAnimateOption(1.1, 1);
    // 事件处理
    nodeAPI->registerNodeEventReceiver(&OnEventReceive);
    // 添加button
    nodeAPI->addChild(rootNode, createAnimateButton);
    nodeAPI->addChild(rootNode, backGroundColorButton);
    nodeAPI->addChild(rootNode, opacityButton);
    nodeAPI->addChild(rootNode, fontSizeButton);
    nodeAPI->addChild(rootNode, fontColorButton);
    nodeAPI->addChild(rootNode, rotateButton);
    nodeAPI->addChild(rootNode, onScaleButton);
    nodeAPI->addChild(rootNode, translateButton);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0010(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0010_0", "BUTTON", ARKUI_NODE_BUTTON);
    MotionButtonHandle(nodeAPI, "OnClickButton0010", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0020(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0020_0", "复选框", ARKUI_NODE_CHECKBOX);
    MotionButtonHandle(nodeAPI, "OnClickButton0020", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0030(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0030_0", "垂直布局容器", ARKUI_NODE_COLUMN);
    MotionButtonHandle(nodeAPI, "OnClickButton0030", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0040(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0040_0", "FLEX", ARKUI_NODE_FLEX);
    MotionButtonHandle(nodeAPI, "OnClickButton0040", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0050(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0050_0", "Image", ARKUI_NODE_IMAGE);
    MotionButtonHandle(nodeAPI, "OnClickButton0050", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0060(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0060_0", "文本图片段落", ARKUI_NODE_IMAGE_SPAN);
    MotionButtonHandle(nodeAPI, "OnClickButton0060", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0070(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0070_0", "LIST", ARKUI_NODE_LIST);
    MotionButtonHandle(nodeAPI, "OnClickButton0070", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0080(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0080_0", "加载动画", ARKUI_NODE_LOADING_PROGRESS);
    nodeAPI->addChild(rootNode, createAnimateProgressText);
    MotionButtonHandle(nodeAPI, "OnClickButton0080", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0090(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0090_0", "进度条", ARKUI_NODE_PROGRESS);
    MotionButtonHandle(nodeAPI, "OnClickButton0090", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0100(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0100_0", "水平布局容器", ARKUI_NODE_ROW);
    MotionButtonHandle(nodeAPI, "OnClickButton0100", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0110(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0110_0", "滚动容器", ARKUI_NODE_SCROLL);
    MotionButtonHandle(nodeAPI, "OnClickButton0110", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0120(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0120_0", "SPAN", ARKUI_NODE_SPAN);
    MotionButtonHandle(nodeAPI, "OnClickButton0120", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0130(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0130_0", "堆叠容器", ARKUI_NODE_STACK);
    MotionButtonHandle(nodeAPI, "OnClickButton0130", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0140(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0140_0", "翻页容器", ARKUI_NODE_SWIPER);
    MotionButtonHandle(nodeAPI, "OnClickButton0140", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0150(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0150_0", "文本", ARKUI_NODE_TEXT);
    MotionButtonHandle(nodeAPI, "OnClickButton0150", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0160(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0160_0", "多行文本", ARKUI_NODE_TEXT_AREA);
    MotionButtonHandle(nodeAPI, "OnClickButton0160", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0170(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0170_0", "状态开关", ARKUI_NODE_TOGGLE);
    MotionButtonHandle(nodeAPI, "OnClickButton0170", rootNode);
}

void UIMotionAnimationCapi::CreateNativeNodeMotionAnimationCapi0180(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    // 创建动画
    createAnimateButton = CreateBaseNodeWithIDAndName(nodeAPI, "OnClickButton0180_0", "xcomponent", ARKUI_NODE_XCOMPONENT);
    MotionButtonHandle(nodeAPI, "OnClickButton0180", rootNode);
}

} // namespace ArkUICApiDemo